home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
fortran
/
mslang
/
vax2pc
/
vax2pc.for
Wrap
Text File
|
1994-06-15
|
9KB
|
274 lines
c
c VAX2PC.FOR
c
c Programmed by Mike Shefler
c CONSAD Research Corporation
c 121 North Highland Avenue
c Pittsburgh, PA 15206-3050
c (412) 363-5500 (voice)
c (412) 363-5509 (FAX)
c CIS: 70027,36
c
c Hereby placed in the public domain.
c Not responsible for any damages arising from the use
c of this program.
c
c This program converts a VAX FORTRAN program to Microsoft format.
c The following conversions are performed:
c 1. Lines are output in "standard line format", i.e. they start
c in column 7 and go out to column 72. Tabs are replaced with
c blanks. The parameter TAB_SIZE can be used to adjust the tabs.
c 2. Parameter statements of the form "PARAMETER X=2" are converted
c to the form "PARAMETER (X=2)".
c 3. The VAX-style INCLUDE directive is changed to PC-style.
c 4. Statements of the form "TYPE *," are converted to "WRITE *,"
c 5. The keywords "Readonly" and "Carriagecontrol=whatever" are
c removed from OPEN statements.
c 6. Replaces the ",$)" string in FORMAT statements with the
c PC equivalent ",\)".
c
c The input file is assumed to have an extension of .FVR and the
c output file will have an extension of .FOR.
c
PROGRAM VAX2PC
IMPLICIT NONE
CHARACTER TAB_CHAR*(*)
PARAMETER (TAB_CHAR = ' ')
INTEGER TAB_SIZE
PARAMETER (TAB_SIZE = 4)
CHARACTER FileName*8, Line*132, Out*132, c*1, InFile*12, OuFile*12
CHARACTER Temp*132
INTEGER n1, p, q, r, p1, p2, p3
LOGICAL InQuote, InComment, IsDigit, StillDigit, IsOnDisk, Acomma
c----------------------------------------------------------------------------
99 WRITE (*,1)
1 FORMAT (' Enter the Filename to convert (no ext implies .FVR):'\)
READ (*,2) FileName
2 FORMAT (a)
IF (INDEX(FileName,'.') .LE. 0) THEN ! Add extension of .FVR
InFile = FileName(:Len_Trim(FileName)) // '.FVR'
OuFile = FileName(:Len_Trim(FileName)) // '.FOR'
ELSE
InFile=FileName
p = INDEX(FileName,'.')
OuFile = FileName(:p) // '.FOR'
ENDIF
c
c Check for files' existence. If input doesn't, then re-ask. If
c output does, confirm overwrite.
c
INQUIRE (File=InFile, Exist=IsOnDisk)
IF (.NOT. IsOnDisk) THEN
WRITE (*,*) ' That file doesn''t exist, try again.'
GOTO 99
ENDIF
INQUIRE (File=OuFile, Exist=IsOnDisk)
IF (IsOnDisk) THEN
WRITE (*,3)
3 FORMAT (' That file already exists. OK to overwrite (Y/N)?'\)
READ (*,2) c
IF (c .NE. 'y' .AND. c .NE. 'Y') GOTO 99
ENDIF
OPEN (Unit=1, File=InFile, Status='OLD')
OPEN (Unit=2, File=OuFile, Status='UNKNOWN')
c----------------------------------------------------------------------------
c
c Process each line individually. It may look messy on output if you
c have continuation lines that are over 80 characters, but that's the
c price you pay.
c
100 READ (1,2,End=199) Line
n1 = n1 + 1
c
c Change VAX-style INCLUDE statements to MS-style
c
IF (INDEX(Line,'INCLUDE ''') .GT. 0
1.OR. INDEX(Line,'Include ''') .GT. 0
2.OR. INDEX(Line,'include ''') .GT. 0) THEN
p = INDEX(Line,'''')
Out = '$INCLUDE: ' // Line(p:)
GOTO 150
ENDIF
c
c Change VAX-style PARAMETER statements (without parens) to MS-style
c (with parens). Have to be careful not to include inline comments
c inside the parens.
c
p1 = INDEX(Line,'PARAMETER ')
p2 = INDEX(Line,'Parameter ')
p3 = INDEX(Line,'parameter ')
p = MAX(p1,p2,p3)
q = INDEX(Line,'!') ! Look for inline comment
r = INDEX(Line,'(') ! And see if paren already there
IF (p .GT. 0 .AND. p .LT. 10 .AND. (r .EQ. 0 .OR. r .GT. q)) THEN
p = p + 9
IF (q .LE. 0) THEN
Out = Line(:p) // '(' // Line(p+1:Len_Trim(Line)) // ')'
ELSE
Out = Line(:p) // '(' // Line(p+1:q-1) // ') ' // Line(q:)
ENDIF
Line = Out
GOTO 120
ENDIF
c
c Replace VAX-style TYPE *,whatever with the MS-style WRITE (*,*)whatever
c
p1 = INDEX(Line,'TYPE *,')
p2 = INDEX(Line,'Type *,')
p3 = INDEX(Line,'type *,')
p = MAX(p1,p2,p3)
IF (p .GT. 0) THEN
Out = Line(:p-1) // 'WRITE (*,*)' // Line(p+7:)
Line = Out
GOTO 120
ENDIF
c
c Remove the READONLY and CARRIAGECONTROL parameters from OPEN statements.
c
p1 = INDEX(Line,'READONLY')
p2 = INDEX(Line,'Readonly')
p3 = INDEX(Line,'readonly')
p = MAX(p1,p2,p3)
IF (p .GT. 0) THEN
q = p + 8
Acomma = .FALSE.
DO WHILE (p .GT. 0 .AND. .NOT. Acomma)
IF (Line(p:p) .EQ. ',') Acomma = .TRUE.
p = p - 1
ENDDO
IF (p .GT. 0) THEN
Temp = Line(:p) // Line(q:)
Line = Temp
ENDIF
GOTO 120
ENDIF
p1 = INDEX(Line,'CARRIAGECONTROL=')
p2 = INDEX(Line,'Carriagecontrol=')
p3 = INDEX(Line,'carriagecontrol=')
p = MAX(p1,p2,p3)
IF (p .GT. 0) THEN
p1 = INDEX(Line(p+17:),'''') + 17
q = p + p1
Acomma = .FALSE.
DO WHILE (p .GT. 0 .AND. .NOT. Acomma)
IF (Line(p:p) .EQ. ',') Acomma = .TRUE.
p = p - 1
ENDDO
IF (p .GT. 0) THEN
Temp = Line(:p) // Line(q:)
Line = Temp
ENDIF
GOTO 120
ENDIF
c
c Change VAX-style "$" formatting code to MS-equivalent "\".
c
q = Len_Trim(Line)
p1 = INDEX(Line,'FORMAT')
p2 = INDEX(Line,'Format')
p3 = INDEX(Line,'format')
p = MAX(p1,p2,p3)
IF (p .GT. 0) THEN
IF (Line(q-2:q-1) .EQ. ',$') THEN
Line(q-1:q-1) = '\'
GOTO 120
ENDIF
ENDIF
c----------------------------------------------------------------------------
c Here is where the line is output and reformatted to 72 characters.
c If the first character is a tab, then it's either a beginning line
c or a continuation line. If the character after the tab is a digit 1-9
c then it's a continuation line. Begin building the output line.
c p is the position in Line and q in Out.
c
120 Out = ' '
IF (Line(1:1) .EQ. TAB_CHAR) THEN
IF (IsDigit(Line(2:2))) THEN
Out(6:6) = Line(2:2)
p = 3
ELSE
p = 2
ENDIF
q = 7
ELSEIF (IsDigit(Line(1:1))) THEN
p = 1
q = 1
StillDigit = IsDigit(Line(p:p))
DO WHILE (StillDigit)
Out(q:q) = Line(p:p)
q = q + 1
p = p + 1
StillDigit = IsDigit(Line(p:p))
ENDDO
p = p + 1
q = 7
ELSE
Out = Line
GOTO 150
ENDIF
c
c For remainder of line, test for length exceeding 72 and start a new
c continuation line if necessary. Don't continue if the excess is an
c inline comment (!...) but check for being quoted first. Tabs not in
c quotes are replaced with TAB_SIZE blanks.
c
InQuote = .FALSE.
InComment = .FALSE.
125 DO WHILE (q .LE. 72 .AND. p .LE. Len_Trim(Line))
IF (Line(p:p) .EQ. TAB_CHAR .AND. .NOT. InQuote) THEN
q = q + TAB_SIZE
p = p + 1
CYCLE
ELSE
Out(q:q) = Line(p:p)
ENDIF
IF (Line(p:p) .EQ. '''') THEN
InQuote = .NOT. InQuote
ELSEIF (Line(p:p) .EQ. '!' .AND. .NOT. InQuote) THEN
InComment = .TRUE.
ENDIF
p = p + 1
q = q + 1
ENDDO
IF (InComment) Out(q:) = Line(p+1:)
IF (p .LE. Len_Trim(Line) .AND. .NOT. InComment) THEN
WRITE (2,2) Out(:Len_Trim(Out))
Out = ' +'
q = 7
GOTO 125
ENDIF
150 IF (Len_Trim(Out) .GT. 0) THEN
WRITE (2,2) Out(:Len_Trim(Out))
ELSE
WRITE (2,2) ' '
ENDIF
GOTO 100
199 STOP
END
c----------------------------------------------------------------------------
c
c This function is used because the MS Powerstation VERIFY function
c doesn't work as advertised.
c
LOGICAL FUNCTION IsDigit(C)
CHARACTER C*1
IF (C .LT. '0' .OR. C .GT. '9') THEN
IsDigit = .FALSE.
ELSE
IsDigit = .TRUE.
ENDIF
RETURN
END
c----------------------------------------------------------------------------